package com.hskn.hss.module.casesetissuesource.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.carTrackOriginal.mapper.CarTrackOriginalMapper;
import com.hskn.hss.module.casesetissue.entity.CasesetIssue;
import com.hskn.hss.module.casesetissuesource.entity.CasesetIssueSource;
import com.hskn.hss.module.casesetissuesource.mapper.CasesetIssueSourceMapper;
import com.hskn.hss.module.casesetissuesource.service.ICasesetIssueSourceService;
import com.hskn.hss.module.tlequip.entity.TlEquip;
import com.hskn.hss.module.tlequip.mapper.TlEquipMapper;
import com.hskn.hss.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-18
 */
@Slf4j
@RestController
@RequestMapping("/hss/casesetissuesource")
public class CasesetIssueSourceController {

    @Autowired
    private ICasesetIssueSourceService casesetIssueSourceService;

    @RequestMapping(value = "list", method = RequestMethod.POST)
    public AjaxResult<Object> list(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            List<CasesetIssueSource> casesetIssueSources = casesetIssueSourceService.mList(params);
            return AjaxResult.success(casesetIssueSources);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.INSERT, tableName = "caseset_issue_source", bean = CasesetIssueSource.class, beanMapper = CasesetIssueSourceMapper.class, names = "name")
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public AjaxResult<Object> add(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesetIssueSourceService.add(params);
            return AjaxResult.success("发布成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "caseset_issue_source", idKey = "casesetIssueSourceId", bean = CasesetIssueSource.class, beanMapper = CasesetIssueSourceMapper.class, names = "name")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public AjaxResult<Object> update(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesetIssueSourceService.mUpdate(params);
            return AjaxResult.success("修改成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.DELETE, tableName = "caseset_issue_source", idKey = "casesetIssueSourceId", bean = CasesetIssueSource.class, beanMapper = CasesetIssueSourceMapper.class, names = "name")
    @RequestMapping(value = "del", method = RequestMethod.POST)
    public AjaxResult<Object> del(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesetIssueSourceService.del(params);
            return AjaxResult.success("删除成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

}

